package com.ddxcloud.common.utils;

import cn.hutool.crypto.symmetric.SymmetricCrypto;
import com.ddxcloud.common.utils.config.SuihbConfig;

public class Sm4Util {

    //指明加密算法和秘钥
    static SymmetricCrypto sm4 = new SymmetricCrypto("SM4/ECB/PKCS5Padding", SuihbConfig.SM4_KEY.getBytes());

    //加密为16进制，也可以加密成base64/字节数组
    public static String encryptSm4(String plaintext) {
        return sm4.encryptHex(plaintext);
    }

    //解密
    public static String decryptSm4(String ciphertext) {
        return sm4.decryptStr(ciphertext);
    }

    public static void main(String[] args) {
        String content = "Gm5Zl5x7Sr6q18ScqC2u8a6JwapSzk";
        String plain = encryptSm4(content);
        String cipher = decryptSm4("619b3d172c4911a9");
        System.out.println(plain +  "\n" + plain.length() +"\n" + cipher);
    }

}
